var PRODUCT_PATH = "";
function setPathPrefix(productPath) {
	PRODUCT_PATH = productPath;
}

$(function () {
	var app = {
		init: function () {
			
			this.getIndustryDynamics();
			this.getHotSale();
			this.getTodoCount();
			this.bind();
		},
		bind: function () {
			
		},
		//获取行业动态
		getIndustryDynamics: function () {
			$.get("/solution/business/prdSetup/news/homeNews.do", function(data) {
				if(data) {
					var arr = [];
					for(var i = 0; i < data.length; i++) {
						var obj = {};
						
						obj.id = data[i].id;
						obj.title = data[i].newsTitle;
						obj.content = data[i].newsAbstract;
						obj.date = data[i].createTime;
						
						arr.push(obj);
					}
					
					var d = {result: {
						'first': arr[0],
						'second': arr[1]
					}};
			        var $tpl = $('#template1').html();
			        var html = Mustache.render($tpl, d);
			        $('#dynamics').html(html);
				}
			}, 'json');
//			var data = [{
//				'title': '招商基金旗下部分基金增加百度百盈...',
//				'content': '招商基金旗下部分基金增加百度百盈为代销机构及参与其费率优惠活动的公告...',
//				'date': '2018-11-20'
//			},
//			{
//				'title': '招商可转债分级债券型证券投资基金可能...',
//				'content': '由于近期可转债市场波动较大，截止2019年1月22日，招商转债B份额的基金份额净值接近基金合同规定...',
//				'date': '2018-11-20'
//			}];
		},
		//获取热销产品
		getHotSale: function () {
			var actionUrl = PRODUCT_PATH + "getSellWellPrd.do";
			$.ajax({
				type : 'POST',
				url : actionUrl,
				dataType : 'json',
				success : function(sellWellPrdList) {
					var data = [];
					var prdJson = {};
					$.each($.parseJSON(sellWellPrdList),function(i,project){
						var performanceFees = project.yield;
						if(performanceFees){
							var firstNum = "";
							var decimal = "";
							if(performanceFees.indexOf('.') > 0){
								firstNum = performanceFees.substring(0,performanceFees.indexOf('.'));
								decimal = performanceFees.substring(performanceFees.indexOf('.')+1,performanceFees.length);
								firstNum = '<span class="first-num">' + firstNum + '</span>.' + decimal + ' %';
							}else{
								firstNum = '<span class="first-num">' + performanceFees + '</span>.0 %';
							}
							
						}
						prdJson = {
								'prdCode' : project.subPrdCode,
								'title': project.subFundSname,
								'firstNum': firstNum
							};
						data.push(prdJson);
					});
					
					var d = {result: data};
			        var $tpl = $('#template2').html();
			        var html = Mustache.render($tpl, d);
			        $('#sale').html(html);
				},
				error : function(xhr) {
					sweetAlertAjaxError(xhr);
				}
			});
		},
		
		getTodoCount: function () {
			var actionUrl = "/solution/business/myHome/todoAndOutput/queryTodoCount.do";
			$.ajax({
				type : 'POST',
				url : actionUrl,
				dataType : 'json',
				success : function(data) {
					if(data.object && data.object > 0) {
						$(".my-circle").show();
						var count = data.object * 1;
						if(count > 99) {
							$(".my-circle").html("99+");
						} else {
							$(".my-circle").html(count);
						}
					} else {
						$(".my-circle").hide();
					}
				}
			});
		}
	};
	
	app.init();
	
	// 定时刷新数据
    setInterval(function(){
    	app.getTodoCount();
	}, 30000);
    
    $("#user-info").mouseover(function (){  
        $(".user-oper-div").show();  
    }).mouseout(function (){  
        $(".user-oper-div").hide();  
    });
    $(".user-oper-div").mouseover(function (){  
    	$(".user-oper-div").show();  
    }).mouseout(function (){  
    	$(".user-oper-div").hide();  
    });
});